********************************
***Polarization Scenarios***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==1  {
cap cd "~\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
global draftout "../../Draft/Figures/"
} 

use 3_clean_data, replace

/*
*******************
Base Polarization Scenarios:
Own Leader:
1. With Prior - Total:  (5, Republican) & (2, Democrat) & 0
2. With Prior - Anonymous Message:  (7, Republican) & (4, Democrat) & 0
3. With Prior - Persuasion:  (7 & 5, Republican) & (4 & 2, Democrat)
4. Against Prior - Total:  (1, Republican) & (6, Democrat) & 0
5. Against Prior - Anonymous Message:  (3, Republican) & (8, Democrat) & 0
6. Against Prior - Persuasion:  (3 & 1, Republican) & (8 & 6, Democrat)

Opposition Leader: 
1. With Prior - Total:  (6, Republican) & (1, Democrat) & 0
2. With Prior - Anonymous Message:  (8, Republican) & (3, Democrat) & 0
3. With Prior - Persuasion:  (8 & 6, Republican) & (3 & 1, Democrat)
4. Against Prior - Total:  (2, Republican) & (5, Democrat) & 0
5. Against Prior - Anonymous Message:  (4, Republican) & (7, Democrat) & 0
6. Against Prior - Persuasion:  (4 & 2, Republican) & (7 & 5, Democrat)

Outcome is always anti

Structure: 
		& 		 & Polarization Change &  Control Mean
Message & Source & Control & \beta & (S.E.)  & \%Diff. & Republican & Democrat & N 
Party vs. Not & Leader vs. Opposition
*/

gen trump=treat==1 | treat==3 | treat==5 | treat==7 | treat==9
gen obama=trump==0 & treat>0
gen ownleader=trump if recruit==0
replace ownleader=obama if recruit==1
gen oppleader=1-ownleader
replace ownleader=1 if treat==0
replace oppleader=1 if treat==0

gen anti=treat>4 & treat<9
gen pro=treat>0 & treat<5
gen withprior=anti if recruit==0
replace withprior=pro if recruit==1
gen againstprior=1-withprior
replace withprior=1 if treat==0 | treat==9 | treat==10
replace againstprior=1 if treat==0 | treat==9 | treat==10

*4 Scenarios/Groups*
*1: With Prior, Own Leader
gen group1=ownleader==1 & withprior==1
*2: With Prior, Opposing Leader
gen group2=oppleader==1 & withprior==1
*3: Against Prior, Own Leader 
gen group3=ownleader==1 & againstprior==1
*4: Against Prior, Opposing Leader 
gen group4=oppleader==1 & againstprior==1

gen repub=recruit==0

gen president=treatment==1 | treatment==2 | treatment==5 | treatment==6
gen actor=treatment==3 | treatment==4 | treatment==7 | treatment==8
gen turkey= treatment==9 | treatment==10
gen priming=turkey==1 | president==1
gen message=actor==1 | president==1

/*
*For Total Effect*
ln(p(anti)+1)=b0+b1*republican+b2*president+b3*republican*president 
b3 is total change in polarization
*For Decomposition Effect*
ln(p(anti)+1)=0+b1*republican+b2*message+b3*president 
	+b4*republican*message+b5*republican*president
b4 is anonymous message change in polarization
b5 is persuasion change in polarization
*/

gen repub_president=repub*president
gen repub_message=repub*message
gen repub_priming=repub*priming

*********************************
***MAIN SCENARIOS***
*********************************

*********************************
***Create Variables and Format***
*********************************
	
global lasso0 hispanic age55_64 candidate16_hillary candidate16_other ///
	immlevel_decrease gun_lessstrict abortion_illegal tax_toohigh health_notgvt ///
	occ_twitter occ_buzzfeed trumpfan lebronfan taylorfan bgatesfan ///
	obamafan obama_neutral topissue_health 
	
global lasso1 black hispanic age35_44 age45_54 hsdegree ///
	candidate16_hillary immlevel_decrease immlevel_same ///
	gun_same gun_lessstrict abortion_partlegal abortion_illegal tax_toohigh ///
	health_neutral health_notgvt i.freq_nytimes ///
	daily_tv occ_tv daily_newspaper i.freq_fox week_breitbart ///
	daily_breitbart occ_buzzfeed ///
	lebron_neutral obamafan trump_neutral trumpfan west topissue_tax 
	

global message1 "Message With Prior"
global message2 "Message With Prior"
global message3 "Message Against Prior"
global message4 "Message Against Prior"
global leader1 "Own Leader"
global leader2 "Opposing Leader"
global leader3 "Own Leader"
global leader4 "Opposing Leader"

global effect1 "Total"
global effect2 "Anonymous Message"
global effect3 "Persuasion"
global effect4 "Total"
global effect5 "Anonymous Message"
global effect6 "Persuasion"

global dir0 "anti"
global dir1 "pro"


foreach y in 1 2 4 5 {
	global space`y' "[.2em]" 
	} 
foreach y in 3 {
	global space`y' "[1em]" 
	} 
foreach y in 6 {
	global space`y' "[1em]" 
	} 


*********************************************************
*********************************************************
******Create Plot Version******
*********************************************************
*********************************************************


gen n=_n if _n<13

gen own=n<=3 | (n>=7 & n<=9)
gen opp=1-own if own!=.
gen againstp=n>=7

*Labels*
label define ownopp ///
	0 `" "Own" "Leader" "' ///
	1 `" "Opposition" "Leader" "', replace 
label values opp ownopp	

label define withagainst ///
	0 `" "With Prior" " " " "' /// 
	1 `" "Against Prior" " " "', replace
label values againstp withagainst	

	
label values n ta
gen totp=.
gen messp=.
gen presp=.

*1: With Prior, Own
*2: With Prior, Opposition
*3: Against Prior, Own
*4: Against Prior, Opposition

local n = 0

foreach y of numlist 1/4 {

	reg ln1_prob_index_anti president repub repub_president ///
		$lasso0 $lasso1 if (group`y'==1) & actor==0 & turkey==0, robust

	sum prob_index_anti if treat==0 & repub==0 & e(sample)==1
	local d = r(mean)
	sum prob_index_anti if treat==0 & repub==1 & e(sample)==1
	local r = r(mean)
	local c = (_b[president]+_b[repub_president])*(`r'+1)-_b[president]*(`d'+1)
	local c = round(`c'/(`r'-`d')*10000)/100
	local c : di  %6.2f `c'	
	
	local n = `n'+1
	replace totp=`c' if n==`n'
	
	reg ln1_prob_index_anti message president repub repub_message repub_president ///
		$lasso0 $lasso1 if (group`y'==1) & turkey==0, robust

	sum prob_index_anti if treat==0 & repub==0 & e(sample)==1
	local d = r(mean)
	sum prob_index_anti if treat==0 & repub==1 & e(sample)==1
	local r = r(mean)
	local c = (_b[message]+_b[repub_message])*(`r'+1)-_b[message]*(`d'+1)
	local c = round(`c'/(`r'-`d')*10000)/100
	local c : di  %6.2f `c'	
	
	local n = `n'+1
	replace messp=`c' if n==`n'

	sum prob_index_anti if treat==0 & repub==0 & e(sample)==1
	local d = r(mean)
	sum prob_index_anti if treat==0 & repub==1 & e(sample)==1
	local r = r(mean)
	local c = (_b[president]+_b[repub_president])*(`r'+1)-_b[president]*(`d'+1)
	local c = round(`c'/(`r'-`d')*10000)/100
	local c : di  %6.2f `c'	
	
	local n = `n'+1
	replace presp=`c' if n==`n'

}

*President vs. Actor*
# delimit ;

graph bar totp messp presp if n<13, over(opp) over(againstp) 	
	bar(1, color(black))
	bar(2, color(gray) lcolor(black)) 
	bar(3, color(white) lcolor(black)) 
	blabel(bar, format(%6.1f) position(outside) size(vsmall))
	bargap(8)
	graphregion(color(white)) 
	yline(0, lcolor(gray))
	yscale(range(-35(10)15)) ylabel(-35(10)15, nogrid) 
	ytitle("% Polarization Change" " ")
	legend(order(1 "Total" 
	2 "Anonymous Message" 3 "Source Persuasion" ) rows(3) )
	ylabel(-40(10)20, nogrid)  yscale(range(-40(10)20))
	;
	# delimit cr

graph export "$draftout/8_PolarizationPlot_MessageFixed_VarySource.eps", replace	

